package com.zline.foodraise.view;

import android.content.Context;
import android.view.View;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.zline.foodraise.R;
import com.zline.foodraise.entity.UserAddressBean;
import com.zline.foodraise.listener.RecyclerItemClicked;

import org.androidannotations.annotations.Click;
import org.androidannotations.annotations.EViewGroup;
import org.androidannotations.annotations.ViewById;

/**
 * Created by heshantao on 15/12/23.
 * 地址管理每条地址Item
 */
@EViewGroup(R.layout.shipping_addr_item)
public class ShippingAddrItem extends RelativeLayout {
    private static final String LOG_TAG=ShippingAddrItem.class.getSimpleName();
    RecyclerItemClicked itemClicked;
    int position;
    @ViewById(R.id.addr_manager_name_tv)
    TextView userName;
    @ViewById(R.id.addr_manager_phone_tv)
    TextView userPhone;
    @ViewById(R.id.addr_manager_addr_tv)
    TextView userAddr;


    public ShippingAddrItem(Context context) {
        super(context);
    }

    public void bind(int position,UserAddressBean addressBean){
        this.position=position;
        if(addressBean!=null){
            String addr = addressBean.getPreAddr() + addressBean.getSubAddr() + addressBean.getDetailAddr();
            userAddr.setText(addr);
            userName.setText(addressBean.getReceiverName());
            userPhone.setText(addressBean.getReceiverMobile());

        }
    }


    public void setListener(RecyclerItemClicked listener) {
        this.itemClicked = listener;
    }

    @Click({R.id.swipelistview_front_rl,R.id.addr_list_delete_tv})
    void onClick(View view){
        switch (view.getId()){
            case R.id.swipelistview_front_rl:
                itemClicked.onRecyclerItemClicked(position);
            break;
            case R.id.addr_list_delete_tv:
                itemClicked.onRecyclerClickedDelete(position);
            break;
            default:
                break;

        }
    }
}
